package com.xjh.mange.controller;

import com.xjh.mange.model.ThingFinishTime;
import com.xjh.mange.service.ThingFinishTimeService;
import com.xjh.mange.vo.Chart;
import com.xjh.mange.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * @author 徐佳辉
 * @date 2020/12/28 23:04
 */
@Controller
@RequestMapping("/chart")
public class ChartController {
    @Autowired
    private ThingFinishTimeService thingFinishTimeService;


    @GetMapping("data")
    @ResponseBody
    public ResponseVO<HashMap<String, Chart>> data() {
        List<ThingFinishTime> list = thingFinishTimeService.list();
        Chart w = thingFinishTimeService.week(list);
        Chart m = thingFinishTimeService.month(list);
        Chart y = thingFinishTimeService.year(list);
        Chart all = thingFinishTimeService.all(list);
        HashMap<String, Chart> hashMap = new HashMap<String, Chart>();
        hashMap.put("week", w);
        hashMap.put("month", m);
        hashMap.put("year", y);
        hashMap.put("all", all);
        return ResponseVO.ok(hashMap);
    }
}
